/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeuristicMessage;
/*   4:    */ import java.util.Hashtable;
/*   5:    */ import java.util.Stack;
/*   6:    */ import java.util.Vector;
/*   7:    */ 
/*   8:    */ abstract class Result
/*   9:    */ {
/*  10:    */   public static final int ALL_OK = 0;
/*  11:    */   public static final int HEUR_HAZARD = 1;
/*  12:    */   public static final int HEUR_MIXED = 2;
/*  13:    */   public static final int HEUR_ROLLBACK = 3;
/*  14:    */   public static final int HEUR_COMMIT = 4;
/*  15:    */   public static final int ALL_READONLY = 5;
/*  16:    */   public static final int ROLLBACK = 6;
/*  17: 50 */   protected int result_ = -1;
/*  18: 53 */   protected int messagecount_ = 0;
/*  19: 56 */   protected Stack replies_ = new Stack();
/*  20: 59 */   protected Hashtable repliedlist_ = new Hashtable();
/*  21: 62 */   protected Vector msgvector_ = new Vector();
/*  22: 65 */   protected Vector errmsgvector_ = new Vector();
/*  23:    */   
/*  24:    */   public Result(int messagecount)
/*  25:    */   {
/*  26: 79 */     this.messagecount_ = messagecount;
/*  27:    */   }
/*  28:    */   
/*  29:    */   public int getResult()
/*  30:    */     throws IllegalStateException, InterruptedException
/*  31:    */   {
/*  32: 95 */     analyze();
/*  33: 96 */     return this.result_;
/*  34:    */   }
/*  35:    */   
/*  36:    */   protected synchronized void addMessages(HeuristicMessage[] marr)
/*  37:    */   {
/*  38:107 */     if (marr == null) {
/*  39:108 */       return;
/*  40:    */     }
/*  41:110 */     for (int i = 0; i < marr.length; i++) {
/*  42:111 */       this.msgvector_.addElement(marr[i]);
/*  43:    */     }
/*  44:    */   }
/*  45:    */   
/*  46:    */   protected synchronized void addErrorMessages(HeuristicMessage[] marr)
/*  47:    */   {
/*  48:124 */     if (marr == null) {
/*  49:125 */       return;
/*  50:    */     }
/*  51:127 */     for (int i = 0; i < marr.length; i++) {
/*  52:128 */       this.errmsgvector_.addElement(marr[i]);
/*  53:    */     }
/*  54:    */   }
/*  55:    */   
/*  56:    */   protected abstract void analyze()
/*  57:    */     throws IllegalStateException, InterruptedException;
/*  58:    */   
/*  59:    */   public HeuristicMessage[] getMessages()
/*  60:    */     throws IllegalStateException, InterruptedException
/*  61:    */   {
/*  62:158 */     analyze();
/*  63:160 */     if (this.msgvector_.isEmpty()) {
/*  64:161 */       return null;
/*  65:    */     }
/*  66:163 */     Object[] oarr = this.msgvector_.toArray();
/*  67:164 */     HeuristicMessage[] ret = new HeuristicMessage[oarr.length];
/*  68:165 */     for (int i = 0; i < ret.length; i++) {
/*  69:166 */       ret[i] = ((HeuristicMessage)oarr[i]);
/*  70:    */     }
/*  71:168 */     return ret;
/*  72:    */   }
/*  73:    */   
/*  74:    */   public HeuristicMessage[] getErrorMessages()
/*  75:    */     throws IllegalStateException, InterruptedException
/*  76:    */   {
/*  77:185 */     analyze();
/*  78:187 */     if (this.errmsgvector_.isEmpty()) {
/*  79:188 */       return null;
/*  80:    */     }
/*  81:190 */     Object[] oarr = this.errmsgvector_.toArray();
/*  82:191 */     HeuristicMessage[] ret = new HeuristicMessage[oarr.length];
/*  83:192 */     for (int i = 0; i < ret.length; i++) {
/*  84:193 */       ret[i] = ((HeuristicMessage)oarr[i]);
/*  85:    */     }
/*  86:195 */     return ret;
/*  87:    */   }
/*  88:    */   
/*  89:    */   public synchronized void addReply(Reply reply)
/*  90:    */   {
/*  91:207 */     if ((reply.isRetried()) || (this.repliedlist_.containsKey(reply.getParticipant()))) {
/*  92:209 */       return;
/*  93:    */     }
/*  94:215 */     this.repliedlist_.put(reply.getParticipant(), new Object());
/*  95:216 */     this.replies_.push(reply);
/*  96:217 */     this.messagecount_ -= 1;
/*  97:218 */     notifyAll();
/*  98:    */   }
/*  99:    */   
/* 100:    */   public Stack getReplies()
/* 101:    */     throws IllegalStateException, InterruptedException
/* 102:    */   {
/* 103:234 */     waitForReplies();
/* 104:235 */     return this.replies_;
/* 105:    */   }
/* 106:    */   
/* 107:    */   synchronized void waitForReplies()
/* 108:    */     throws InterruptedException
/* 109:    */   {
/* 110:248 */     while (this.messagecount_ > 0) {
/* 111:249 */       wait();
/* 112:    */     }
/* 113:    */   }
/* 114:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.Result
 * JD-Core Version:    0.7.0.1
 */